//
//  AppDelegate.m
//  DMMCalibration
//
//  Created by apple on 17/3/1.
//  Copyright © 2017年 microtest.org. All rights reserved.
//

#import "AppDelegate.h"
#import "Configuration.h"
#import "Engine.h"

@interface AppDelegate ()
{
    
    Engine *eng;
}

@end

@implementation AppDelegate
@synthesize  collectionView = _collectionView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    eng = [[Engine alloc] initWithObject:self.testView];
    [_cbMeasureBoard removeAllItems];
    [_cbMeasureBoard addItemsWithObjectValues:[Configuration instance].devices];
    
    
    self.testView = [[TestView alloc]initWithNibName:@"TestView" bundle:nil];
    [_collectionView addSubview:self.testView.view];
    self.window.viewsNeedDisplay = YES;
    
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}
- (IBAction)init:(id)sender {
    
}

- (IBAction)stop:(NSButton *)sender {
    if ([[sender title] isEqualToString:@"Stop"]) {
        [sender setTitle:@"Continue"];
        [Configuration instance].stop = @"Stop";
    }else{
        [sender setTitle:@"Stop"];
        [Configuration instance].stop = @"Continue";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"unlock" object:self userInfo:nil];
    }
 
}

- (IBAction)calSelectStep:(id)sender {
    
    [_testView startExcute];
    _txvMeasureVoltIndex.stringValue = [Configuration instance].measureVoltIndex;

}

- (IBAction)startCalAll:(id)sender {
    
    [self getValue];
    [NSThread detachNewThreadSelector:@selector(startTest) toTarget:_testView withObject:nil];
    
}

-(void)getValue
{
    [Configuration instance].startVolt = [_pbStartValue stringValue];
    [Configuration instance].stopVolt = [_pbStopValue stringValue];
    [Configuration instance].stepCount = [_pbStepCount stringValue];
    [Configuration instance].measVoltTolerance = [_pbMeasVoltTolerance stringValue];
    [Configuration instance].chananel = [_cbChannel stringValue];
   // [Configuration instance].setPowerSupVoltage = [_pbSetPowSupVoltage stringValue];
    [Configuration instance].save = [NSString stringWithFormat:@"%ld",[_btnSave state]];
    [Configuration instance].measureBoard = [_cbMeasureBoard stringValue];
    //[Configuration instance].setReadVoltOffset = [_pbSetReadVoltOffset stringValue];
}

- (IBAction)setPowSupVoltage:(id)sender
{
    [Configuration instance].setPowerSupVoltage = [_pbSetPowSupVoltage stringValue];
    [_testView setPowSupVolt];
}

- (IBAction)measBoardMeasVolt:(id)sender
{
    [_testView measBoardMeasVoltage];
    _txvMeasboardMeasVolt.stringValue = [Configuration instance].measBoardMeasVolt;
}

- (IBAction)dmmMeasVolt:(id)sender
{
    [_testView dmmMeasVoltage];
    _txvDMMMeasVolt.stringValue = [Configuration instance].dmmMeasVolt;
}

- (IBAction)setReadVoltOffset:(id)sender
{
    _txvMeasureVoltIndex.stringValue = [Configuration instance].measureVoltIndex;
    [Configuration instance].setReadVoltOffset = [_pbSetReadVoltOffset stringValue];
    

    [_testView setReadVoltOffset];
    
    
}

- (IBAction)getReadVoltOffset:(id)sender
{
    [_testView getReadVoltOffset];
    _txvGetReadVoltOffset.stringValue = [Configuration instance].getReadVoltOffset;
}

@end
